package com.quanyan.operative.service.impl;

import com.quanyan.api.APIResponse;
import com.quanyan.common.utils.StringUtil;
import com.quanyan.operative.component.OperativeRedisTemplate;
import com.quanyan.operative.service.WxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Zheng.Ke
 * Date 2016/12/22.
 */
@Service("wxService")
public class WxServiceImpl implements WxService {
    @Autowired
    private OperativeRedisTemplate operativeRedisTemplate;

    @Override
    public APIResponse verifyOpenId(String appId, String openId) {
        if (StringUtil.isBlankOrNull(appId)) {
            return APIResponse.returnFail("appId不能为空");
        }
        if (StringUtil.isBlankOrNull(openId)) {
            return APIResponse.returnFail("openId不能为空");
        }
        String accessToken = operativeRedisTemplate.hget(appId + "_" + openId, "access_token");
        if (StringUtil.isBlankOrNull(accessToken)) {
            return APIResponse.returnFail("用户还未授权或不是合法openId。appId=" + appId + ",openId=" + openId);
        }
        return APIResponse.returnSuccess("合法的openId");
    }

}
